package top.wuyang.study.java24.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

// 监听器的功能是在容器做相关动作的时候会回调
// ServletContextListener会监听到应用程序的启动和关闭
// contextDestroyed方法是程序关闭时被回调
// contextInitialized方法是程序启动完毕时被回调
@WebListener
public class AppListener implements ServletContextListener {
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("应用程序关闭");
    }

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("应用程序启动");
        ServletContext context = sce.getServletContext();
        System.out.println("contextPath:"+context.getContextPath());
        System.out.println("realPath:"+context.getRealPath("/"));
    }



}
